#include<iostream>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
const int N = 1e5 + 10;
int n, k;
int a[N];
map<int, int>mp;
bool check(int x)
{
	mp.clear();
	for (int i = 1; i <= n; i++) {
		mp[a[i]] = 1;
	}
	bool f = 0;
	for (int i = 1; i <= n; i++) {
		if (mp[a[i] + x]) {
			f = 1;
		}
	}
	if (!f || n - 1 < k)return 0;
	return 1;
}
int main()
{
	cin >> n >> k;
	for (int i = 1; i <= n; i++)cin >> a[i];
	if (k == n) {
		cout << 0 << endl;
		return 0;
	}
	sort(a + 1, a + n + 1);
	int l = 0;
	int r = a[n] - a[1];
	if (k == 1) {
		cout << r << endl;
		return 0;
	}
	while (l + 1 < r) {
		int mid = l + r >> 1;
		cout << "mid==" << mid << endl;
		if (check(mid))r = mid;
		else l = mid;
	}
	cout << r << endl;
	return 0;
}